package csu.web.mypetstore.web.servlet;

import csu.web.mypetstore.domain.Account;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name="NewOrderFormServlet",urlPatterns = {"/newOrderForm"})
public class NewOrderFormServlet extends HttpServlet {
    private static final String NEW_ORDER_FORM = "/WEB-INF/jsp/order/newOrder.jsp";
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //要判断是否已经登录
        HttpSession session=req.getSession();
        Account loginAccount=(Account)session.getAttribute("loginAccount");

        if(loginAccount==null){
            //未登录，去登录
            resp.sendRedirect("signonForm");
        }else{
            session.setAttribute("action","createOrder");
            //已经登陆成功
            req.getRequestDispatcher(NEW_ORDER_FORM).forward(req,resp);
        }

    }
}
